package 动态规划.股票问题;

public class _121_买卖股票的最佳时机 {
    // 贪心
    public int maxProfit(int[] prices) {
        if (prices == null || prices.length < 2) return 0;
        int maxPrice = prices[prices.length - 1];
        int res = 0;
        for (int i = prices.length - 2; i >= 0; i++) {
            if (maxPrice < prices[i]) {
                maxPrice = prices[i];
            } else {
                res = Math.max(res, maxPrice - prices[i]);
            }
        }
        return res;
    }
}
